home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7847 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How big is the 0
  5. Date: 19 Feb 1996 20:30:59 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4gamm3$4q7@dawn.mmm.com>
  8. References: <1996Feb17.132420.114207@kuhub.cc.ukans.edu>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. anh@kuhub.cc.ukans.edu wrote:
  13.  
  14. > Hello,
  15.  
  16. > In C, anytime I need to do a null pointer check I would do this:
  17.  
  18. >     MyType *p;
  19.  
  20. >     if(p==(MyType*)0)
  21. >         bla;
  22.  
  23. The cast is not necessary.
  24.  
  25. > The new operator supposedly return a 0 upon failure.
  26.  
  27. Not any more.  It is guaranteed to never return 0.  It will either return
  28. a valid pointer or throw an exception.
  29.  
  30. Of course, if you have an older compiler, all bets are off :-)
  31.  
  32. > Can I rely on the 
  33. > compiler to make sure the 0 is as big as the size of the pointer? For 
  34. > example, ALPHA's pointers are 64 bits long which is different from the 32 bits
  35. > int.
  36.  
  37. Comparing any pointer to a literal 0 will work just fine.
  38. --
  39. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  40. 3M Company                      phone:  (612) 737-4643
  41. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  42. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  43.     But 3M speaks for me -- I did not write the following line:
  44.  
  45. Opinions expressed herein are my own and may not represent those of 3M.
  46.